
const app = getApp();
const api = app.apiInstance
import moment from '../../public/utils/moment'
Page({  
  data: {
    current_scroll: '',
    searchType:1,
    type:'',
    searchForm:{},
    keyWord:'',
    searchList:[{
        id: 1,
        name: '标题',
    }, {
        id: 2,
        name: '文章'
    }],
    fenLeiList:[],
    fenLeiList_v1:[],
    current_scroll_v1:'',
    dataList:[],
    mockList:[],
    bigSearchShow:false,
    isShowSearch:false
  },
  async loadData(){
    await this.getFenLei();
    this.getList()
  },


  onLoad(){
    this.loadData();
  },

  showBigSearch(){
    this.setData({
      bigSearchShow:true
    })
  },

  searchSelect(e){
    console.log('e',e);
    this.setData({
      type:e.detail.dictValue,
      current_scroll_v1:e.detail.dictLabel,
    })
    this.getList();

  },

  async getList(){

    let params ={
      type2:this.data.current_scroll,
      type:this.data.type,
      ...this.data.searchForm,
    }
    const extra = this.data.searchType==1?{title:this.data.keyWord}:{standardRequirement:this.data.keyWord}
    params = Object.assign({},params,extra)
    const {rows} = await api.post('/v1/openApi/laws/search',params);

    rows.forEach(item => {
      item.isNew = moment(item.updateTime).diff(moment("2024-07-11"),"days")<90?true:false
    });
    this.setData({
      dataList : rows,
    })
  },

  async getFenLei(){
    //字典分类
    const {rows} = await api.get('/v1/openApi/dic/data/type/laws_regulations_type_v2');
    this.setData({
      fenLeiList : [{dictLabel:'所有',dictValue:''},...rows],
      current_scroll:''
    })

    //字典分类
    const data = await api.get('/v1/openApi/dic/data/type/laws_regulations_type');
    console.log('data.rows',data.rows)
    this.setData({
      fenLeiList_v1 : data.rows,
      current_scroll_v1:data.rows[0].dictValue,
      type:data.rows[0].dictValue,
    })
  },

  selectItem(e){
    console.log('e',e);
    wx.navigateTo({
      url: `/subPages/faLvZdDetail/faLvZdDetail?id=${e.currentTarget.dataset.item.id}`,
    })
  },
  handleChangeScroll ({ detail }) {
    console.log('detail',detail);
    this.setData({
        current_scroll: detail.key
    });
    this.getList();
  },

  handleSearchChange({detail}){
    this.setData({
      searchTitle: detail.value
    });
  },

  showSearch(){
    this.setData({
      isShowSearch: true
    });
    
  },

  handleOK(){
    this.getList();
    this.setData({
      isShowSearch: false
    });
  },

  handleCancel(){
    this.setData({
      isShowSearch: false
    });
  },

  issuingDepartmentChange(e){
    this.setData({
      'searchForm.issuingDepartment': e.detail.detail.value
    });
  },

  applicableDepartmentChange(e){
    this.setData({
     'searchForm.applicableDepartment': e.detail.detail.value
    });
  },

  numberChange(e){
    this.setData({
     'searchForm.number': e.detail.detail.value
    });
  },

  setKeyword(e){
    this.setData({
      keyWord: e.detail.value
     });
  },

  radioChange(e){
    this.setData({
     'searchType': e.detail.value
    });
  },
 

})
